package hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {
	private static SessionFactory sf;
	private static ServiceRegistry sr;
	private static Configuration cf;
	static{
		try {
			cf=new Configuration().configure();
			sr=new 
			   StandardServiceRegistryBuilder().applySettings(cf.getProperties()).build();
			sf=cf.buildSessionFactory(sr);
		} catch (HibernateException e) {
			System.out.println(e);
			e.printStackTrace();
		}
		
	}
	public static Session getSession(){
		return sf.openSession();
	}
	public static void closSession(Session session){
		session.close();
	}
}
